<?php
/**
 * Created by JetBrains PhpStorm.
 * User: akrug
 * Date: 15.05.12
 * Time: 15:55
 * To change this template use File | Settings | File Templates.
 */
class Plugin_LayoutSwitch extends Zend_Controller_Plugin_Abstract
{
    protected $_layout;

    public function __construct($layout){
        $this->_layout = $layout;
    }

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $module = $request->getModuleName();

        $layoutsDir = $this->_layout->getLayoutPath();

        if(file_exists($layoutsDir.'/'.$module.".phtml")) {
            $this->_layout->setLayout($module);
        } else {
            $this->_layout->setLayout("default");
        }
    }
}
